package com.dognessnetwork.kurento;

import org.kurento.client.KurentoClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import com.dognessnetwork.kurento.Handler.PointerDetectorHandler;
import com.dognessnetwork.kurento.Handler.ZbarHandler;

@EnableWebSocket
@SpringBootApplication
public class KurentoApplication  implements WebSocketConfigurer {

	@Bean
	public CallHandler1 callHandler() {
		return new CallHandler1();
	}
	
	@Bean
	public ZbarHandler zbarHandler() {
		return new ZbarHandler();
	}
	
	@Bean
	  public UserRegistry registry() {
	    return new UserRegistry();
	  }
	
	@Bean
	public CallHandler oneToOneCallHandler() {
		return new CallHandler();
	}
	
	@Bean
	public PointerDetectorHandler handler() {
		return new PointerDetectorHandler();
	}
	
	@Bean
	public KurentoClient kurentoClient() {
		return KurentoClient.create("ws://petnet.imwork.net:8888/kurento");
	}

	public static void main(String[] args) {
		SpringApplication.run(KurentoApplication.class, args);
	}

	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		// TODO Auto-generated method stub
		registry.addHandler(callHandler(), "/call");
		registry.addHandler(zbarHandler(), "/zbar");
		registry.addHandler(oneToOneCallHandler(), "/oto").setAllowedOrigins("*");
	    registry.addHandler(handler(), "/pointerdetector");

	}
}
